import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2023-11-10
 * Time: 9:40
 */
@Component
@Aspect
public class CommentAdvice {

    @AfterReturning("execution(* Car.accelerate(double))")
    public void afterAccelerate() {
        System.out.println("车辆加速，前车注意，我即将超车,(基于注解)");
    }

    @AfterReturning("execution(* Car.decelerate(double))")
    public void afterDecelerate() {
        System.out.println("车辆减速，后车注意减速,(基于注解)");
    }

    @Around("execution(* Car.brake())")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        System.out.println("即将刹车，后车注意减速，基于注解");
        Object object = point.proceed();
        System.out.println("司机注意车辆已静止，基于注解");
        return object;
    }

}
